package com.zy.oauth.controller;


import com.zy.common.core.R;
import com.zy.oauth.dto.AccountDto;
import com.zy.oauth.dto.pream.LoginPream;
import com.zy.oauth.entity.RolePermission;
import com.zy.oauth.service.LoginService;
import com.zy.oauth.service.PermissionService;
import com.zy.oauth.utils.SecurityUtils;
import io.swagger.annotations.Api;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.List;
import java.util.Map;
import java.util.Set;


/**
 * 登录验证
 */
@Api(tags = "贼拉牛逼登陆", value = "贼拉牛逼登陆")
@RestController
public class LoginController {

    @Autowired
    private LoginService service;

    @Resource
    private PermissionService permissionService;

    @PostMapping("/login")
    public R login(@RequestBody LoginPream pream) {
        return R.ok(service.login(pream));
    }

    /**
     * 获取用户信息
     *
     * @return 用户信息
     */
    @GetMapping("info")
    public R info() {
        AccountDto account = SecurityUtils.getLoginUser();
        // 角色集合
        // Set<String> roles = permissionService.getRolePermission(account);
        // 权限集合
        //List<RolePermission> permissions = permissionService.getMenuPermission(roles);
        return R.ok(account);
    }

}
